(function() {
    var editItem = {
        init: function(page, list, renderParam, type, isTop) {
            this.page = page;
            this.list = list;
            this.renderParam = renderParam;
            this.type = type;
            this.isTop = isTop;
            this.text = ''
            this.x = this.y = 0;
            this.r = 0;
        },
        setCountWH(width, height) {
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.countWidth'] = width;
            renderData[this.renderParam + '.countHeight'] = width;
        },
        setTop: function(top) {
            this.top = top;
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.top'] = top;
        },
        setWidth: function(width) {
            this.width = width;
        },
        setHeight: function(height) {
            this.height = height;
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.height'] = height;
        },
        setColor: function(color) {
            this.sliderColor = color;
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.sliderColor'] = color;
        },
        setOpacity: function(opacity) {
            this.opacity = opacity;
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.opacity'] = opacity;
        },
        setText: function(text) {
            this.text = text;
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.text'] = text;
        },
        getText: function() {
            return this.text;
        },
        show: function() {
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.display'] = 'block';
        },
        hide: function() {
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.display'] = 'none';
        },
        disappear: function(callback) {
            this.smoothMoveX(-this.width);
            if (callback) {
                setTimeout(function() {
                    callback();
                }, 180);
            }
        },
        smoothShow: function() {
            this.opacity =  1;
            var animation = wx.createAnimation({duration:150});
            animation.opacity(1).step();
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.animation'] = animation.export();
        },
        smoothHide: function() {
            this.opacity = 0;
            var animation = wx.createAnimation({duration:150});
            animation.opacity(0).step();
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.animation'] = animation.export();
        },
        smoothMoveX: function(x) {
            this.x = x;
            var animation = wx.createAnimation({duration:180, timingFunction:'ease-in-out'});
            animation.translate3d(x, this.y, 0).step();
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.animation'] = animation.export();
        },
        moveX: function(x) {
            this.x = x;
            var animation = wx.createAnimation({duration:0});
            animation.translate3d(x, this.y, 0).step();
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.animation'] = animation.export(); 
        },
        moveY: function(y) {
            this.y = y;
            var animation = wx.createAnimation({duration:0});
            animation.translateY(y).step();
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.animation'] = animation.export();
        },
        rotateX: function(r) {
            if (this.r === r) {
                return;
            }
            this.r = r;
            var animation;
            if (this.isTop) {
                animation = wx.createAnimation({duration:0, transformOrigin:'50% 100% 0'});
            }
            else {
                animation = wx.createAnimation({duration:0, transformOrigin:'50% 0 0'});
            }
          
            animation.rotateX(r).step();
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.animation'] = animation.export();
        },
        smoothRotateX: function(r, callback) {
            var animation;
            if (this.isTop) {
                animation = wx.createAnimation({duration:300, transformOrigin:'50% 100% 0', timingFunction:'ease-in-out'});
            }
            else {
                animation = wx.createAnimation({duration:300, transformOrigin:'50% 0 0', timingFunction:'ease-in-out'});
            }
            animation.rotateX(r).step();
            var renderData = this.page.getRenderData();
            renderData[this.renderParam + '.animation'] = animation.export();
            if (typeof callback === 'function') {
                setTimeout(callback, 300);
            }
        }
    };

    function createEditItem() {
        return Object.create(editItem);
    }

    module.exports = {
        createEditItem:createEditItem
    }
})();